/*
 * 学科
 */

import { createAPI } from '@/utils/request'
import * as URL from '../../constants/api'
const formOfEmploymentMapping = new Map([
  [1, '是'],
  [0, '否'],
])
// 学科列表
export const list = data => createAPI(URL.SUBJECTS, 'get', data)
.then(res => ({
  items: res.data.items.map((p, i) => ({
    ...p,
    index: ++i,
    isFrontDisplay: formOfEmploymentMapping.get(p.isFrontDisplay)
  })),
  counts: res.data.counts,
  page: res.data.page,
  pages: res.data.pages,
  pagesize: res.data.pagesize
}))
.catch(() => {})
.catch(() => {})
// 学科简单列表
export const simple = data => createAPI('/subjects/simple', 'get', data)

// 学科详情
export const detail = data => createAPI(`/subjects/${data.id}`, 'get', data)

// 学科添加
export const add = data => createAPI(URL.SUBJECTS, 'post', data)
.then(res => res)
.catch(() => {})
// 学科修改
export const update = data => createAPI(`${URL.SUBJECTS}/${data.id}`, 'put', data)
.then(res => res)
.catch(() => {})
// 学科删除
export const remove = data => createAPI(`${URL.SUBJECTS}/${data.id}`, 'delete', data)
.then(res => res)
.catch(() => {})
